var wherToLoad="content";
$(document).ready(function() {		   
	//AjaxloderImage for ajax request
	$('#ajaxLoaderGif')
    .hide()  
    .ajaxStart(function() {
        $(this).show();
    })
    .ajaxSuccess(function(e, xhr, settings) {
    	//here controle if is not allowed, or not loged
			})
    .ajaxStop(function() {
        $(this).hide();
    });
	//End AjaxloderImage for ajax request
});	

// get dates
function getDates(range){
	var dates={};
	range=jQuery.trim(range);
	if(range.length==0)return dates;
	if(range.indexOf("-")!=-1){//is a range
		var startDate=range.substring(0,range.indexOf("-")-1);
		startDate=jQuery.trim(startDate);
		var endDate=range.substring(range.indexOf("-")+1);
		endDate=jQuery.trim(endDate);
		dates["startDate"]=startDate;
		dates["endDate"]=endDate;
		return dates;
	}else{
		dates["startDate"]=jQuery.trim(range);
		return dates;
	}
}

function loadContent(refElement,elementID,functionToCall){

	var contextPath=$("#contextPath").val();
	var url;
	
	if(refElement.href==undefined)//not a link element "a"
		url=refElement;
	else// a link element
		url=refElement.href;
	var index=url.indexOf("#");
	if(index>=0){//contains # character
		url=url.substr(url.indexOf("#")+1,url.length);//remove base uri and let only those after #
		window.location.hash = url.substr(0,url.length);
	}
	var toLoad = url;
	var elemID=elementID;
	if(!$(refElement).attr('id')){
		$('#'+elemID).load(toLoad,'',functionToCall);
	}else{
		params="elementId="+refElement.id;
		$('#'+elemID).load(toLoad,params,functionToCall);
	}

	return false;	
}

function executeAction(form,url,divID,functionToCall){
	if(url=='')url=form.action;
	var params= new Array();
	var formElements=form.elements;
	for(i=0 ;i<formElements.length;i++){
		if(formElements[i].type=="checkbox"){//if element is checkbox type, send only checked ones
			if(formElements[i].checked==true){
				params[i]=formElements[i];
			}
		}else if(formElements[i].type=="radio"){//if element is radio type, send only selected ones
			if(formElements[i].checked==true){
				params[i]=formElements[i];
			}
		}else
		params[i]=formElements[i];
	} 
	$("#"+divID).load(url,params,functionToCall);
	form.reset();
	return false;
}

function showTab(element,current) {
	var cur='current1';
	if(current!=null) 
		cur=current;
	$('.tabForm').hide(); 
	$('#'+element).show();
	$('.'+cur).removeClass(cur);
	$('#'+element+'Tab').parent().addClass(cur); 
	return false;
	}


function makeCurrent(element,currentClass,noCurrentClass){
	$('.'+currentClass).removeClass(currentClass).addClass(noCurrentClass);
	$(element).removeClass(noCurrentClass).addClass(currentClass);
	return false;
}

String.prototype.replaceAt=function(index, char) {
    return this.substr(0, index) + char + this.substr(index+char.length);
 };
 
 Array.prototype.exists = function(search){
	  for (var i=0; i<this.length; i++)
	    if (this[i] == search) return true;
			
	  return false;
};
Array.prototype.existsIngnoreCase = function(search){
	  for (var i=0; i<this.length; i++)
	    if ($(this[i]).text().toLowerCase() == $(search).text().toLowerCase()) return true;
			
	  return false;
};
Array.prototype.existsRaw = function(search,field){
	  for (var i=0; i<this.length; i++)
	    if (this[i][field] == search) return i;
			
	  return -1;
};
// Time convert from second
function timeFromSeconds(value) {
	var t = parseInt(value, 10);
        var h = Math.floor(t / 3600);
        t %= 3600;
        var m = Math.floor(t / 60);
        var s = Math.floor(t % 60);
        return (h+":"+m+":"+s);
      /* return (h > 0 ? h + ' hour' + ((h > 1) ? 's ' : ' ') : '') +
                     (m > 0 ? m + ' minute' + ((m > 1) ? 's ' : ' ') : '') +
                     s + ' second' + ((s > 1) ? 's' : '');*/
};


// convert size 
function sizeConvert(value,displayFormat,decimal,legend){
	var value=parseInt(value);
	var convertedFormat=0;
	switch(displayFormat)
	{
	case "TB":
		convertedFormat= parseFloat((value/Math.pow(1000, 4)).toFixed(decimal));
		if(!legend) convertedFormat += " TB";
		break;
	case "GB":
		convertedFormat= parseFloat((value/Math.pow(1000, 3)).toFixed(decimal));
		if(!legend) convertedFormat += " GB";
		break;
	case "MB":
		convertedFormat= parseFloat((value/Math.pow(1000, 2)).toFixed(decimal));
		if(!legend) convertedFormat += " MB";
		break;
	case "KB":
		convertedFormat= parseFloat((value/Math.pow(1000, 1)).toFixed(decimal));
		if(!legend) convertedFormat += " KB";
		break;
	default :
		convertedFormat= parseFloat((value/Math.pow(1000, 3)).toFixed(decimal));
		if(!legend) convertedFormat += " GB";
	}
	return convertedFormat;
	
}

//search object in JSONObject
function getObjects(obj, key, val) {
    var objects = [];
    for (var i in obj) {
        if (!obj.hasOwnProperty(i)) continue;
        if (typeof obj[i] == 'object') {
            objects = objects.concat(getObjects(obj[i], key, val));
        } else if (i == key && obj[key] == val) {
            objects.push(obj);
        }
    }
    return objects;
}
//Convert size value of colone array
Array.prototype.sizeConvertInArray = function(attr,displyFormat,decimal){
	array=this.slice(0);
	$.each(array,function(index,value){
		array[index][attr]=sizeConvert(array[index][attr], displyFormat, decimal,1);
	});
	return array;
};
//index of
Array.prototype.indexOfObject= function(what, index,field){
    index= index || 0;
    var L= this.length;
    while(index< L){
        if(this[index][field]=== what) return index;
        ++index;
    }
    return -1;
};

//Sort Array
Array.prototype.sort(function(a, b){
    a= a.split(':');
    b= b.split(':');
    if(a[1]== b[1]){
        if(a[0]== b[0]) return 0;
        return a[0]> b[0]? 1: -1;
    }
    return a[1]> b[1]? -1: 1;
});

//Calculate min max and avg of jsonArray
Array.prototype.statJsonArray= function(attr){
    var i= 1, item, array= this.slice(0);
    var returnedObject={  'min' : 0 , 'avg' : 0 ,'max' : 0};
    if(array.length>1){
	   returnedObject.max=parseFloat(array[0][attr]);returnedObject.min=parseFloat(array[0][attr]);returnedObject.avg=parseFloat(array[0][attr]);sum=parseFloat(returnedObject.avg);
	    while(i<array.length){
	        item= parseFloat(array[i][attr]);
	        if(item>returnedObject.max) returnedObject.max=parseFloat(item);
	        if(item<returnedObject.min) returnedObject.min=parseFloat(item);
	        sum+=parseFloat(item);
	        ++i;
	    }
	    returnedObject.avg=parseFloat((sum/array.length).toFixed(2));
	    
    }else if(array.length==1){
    	returnedObject.min=returnedObject.avg=returnedObject.max=array[0][attr];
    }else{
    	zebraNotification("Taille du Tableau incorrecte !",3);
    }
    return returnedObject;
};
Number.prototype.roundToSupThousand = function(){
	var str=this+''; var size=str.length;var thousand=parseInt(str.substring(0, 1))+1;
	return Math.pow(10,size-1)*thousand;
	
};
Number.prototype.roundToSubThousand = function(){
	var str=this+''; var size=str.length;
	if(size==1)
		var thousand=0;
	else
		var thousand=parseInt(str.substring(0, 1));
	return Math.pow(10,size-1)*thousand;
	
};
// Split intervale and  count occurence 
Array.prototype.CountOccurenceInterval= function(attr){
    var i= 1, item, array= this.slice(0);
    var statObject={'max' : 0 , 'min' : 0 , 'avg' : 0};
    var returnedObject=[];
    if(array.length>1){
    	statObject.max=array[0][attr];
    	statObject.min=array[0][attr];
    	statObject.avg=array[0][attr];
	   sum=statObject.avg;
	    while(i<array.length){
	        item= array[i][attr];
	        if(item>statObject.max) statObject.max=item;
	        if(item<statObject.min) statObject.min=item;
	        sum+=item;
	        ++i;
	    }
	    statObject.avg=sum/array.length;
	    statObject.min=Math.floor(statObject.min);
	    statObject.max=Math.floor(statObject.max)+1;
	    if(statObject.max>=statObject.min){
	    	var sizeMin=(statObject.min+"").length,sizeMax=(statObject.max+"").length;
	    	var step=0;
	    	if(sizeMax>sizeMin){
	    		step=Math.pow(10, sizeMax-sizeMin);
	    	}else{
	    		step=Math.pow(10, sizeMax-1);
	    	}
	    	var v=0;
	    	statObject.min>0 ? v=statObject.min.roundToSubThousand() : v=0;
	    	if(statObject.min==statObject.max && sizeMax==1){
	    		var obj={'min':v,'max': v+10,'count': array.ArrayCount(v,  v+10,attr)};
	    		if (obj.count!=0) returnedObject.push(obj);
	    	}else if(statObject.min==statObject.max && sizeMax!=1) {
	    		var obj={'min':v,'max': v+step,'count': array.ArrayCount(v,  v+step,attr)};
	    		if (obj.count!=0) returnedObject.push(obj);
	    	}else{
		    	while(v<statObject.max){
		    		var obj={'min':v,'max': v+step,'count': array.ArrayCount(v,  v+step,attr)};
		    		v+=step;
		    		if(v>statObject.max) obj.max=statObject.max;
		    		if (obj.count!=0) returnedObject.push(obj);
		    	}
	    	}
	    }
    }else if(array.length==1){
    	var obj={'min':0,'max': Math.floor(array[0][attr]).roundToSupThousand(),'count': 1};
		returnedObject.push(obj);
    }else{
    	zebraNotification("Taille du Tableau incorrecte !",3);
    }
    return returnedObject;
};

Array.prototype.ArrayCount= function(min,max,attr){
	array=this.slice(0);
	var i=0,count=0;
	while(i<array.length){
		if(array[i][attr]>min && array[i][attr]<=max) count+=1;
		i++;
	}
	return count;
};
//Count frequency occurrence in Array
Array.prototype.frequency= function(attr){
    var i= 0, ax, count, item, a1= this.slice(0);
    var returnedTab=[];
    while(i<a1.length){
        count= 1;
        item= a1[i][attr];
        ax= i+1;
        while(ax<a1.length && (ax= a1.indexOfObject(item, ax,attr))!= -1){
            count+= 1;
            a1.splice(ax, 1);
        }
        //a1[i][attr]+= ':'+count;
        var array=[];array.push(a1[i][attr]);array.push(count);
        returnedTab.push(array);
        ++i;
    }
    return returnedTab;
};
//Ajax request abort 
$.xhrPool = [];
$.xhrPool.abortAll = function() {
  _.each(this, function(jqXHR) {
    jqXHR.abort();
  });
};
//current div envent
$.prototype.makeCurrentEvent = function(){
	$(this).click(function() {
		$("#"+($("#currentDiv").val())).hide();
		$("#"+this.id.split("_")[1]).show();
		$("#currentDiv").val(this.id.split("_")[1]);
		makeCurrent(this,'current','hedTdTop');
	});
};
//hightlite
$.prototype.highlight = function(){
	var id=$(this).attr('id');
	$(this).append("<div id='myToolTip_"+id+"' style='position:absolute;display:none;background:#E5DACA;padding:4px;'></div>")
	.bind('jqplotDataHighlight', function (ev, seriesIndex, pointIndex, data) {
               //$("#myToolTip_"+id).show().html('series: '+seriesIndex+', point: '+pointIndex+', data: '+data);
		$("#myToolTip_"+id).show().html('Value : '+((data+"").split(",")[1]));
    })
    .bind('jqplotDataUnhighlight', function (ev) {
			$("#myToolTip_"+id).hide().html('');
    });
};
// Alert

function zebraAlert(title,message,type){
	$.Zebra_Dialog('<strong>'+message+'</strong>', {
	    'type':     type,
	    'title':    title,
	});
}
function zebraNotification(message,time,type){
	new $.Zebra_Dialog('<strong>'+message+'</strong>', {
		'buttons':  false,
		'modal': false,
		'position': ['right - 20', 'top + 20'],
		'auto_close': time==undefined ? false : time*1000,
		'type' : type==undefined? 'information' : 'warning'
	});
}

// plot bar chart

function plotBarChart(divID,data,title){
	
	$.jqplot(divID, [data], {
		 title:title,
       seriesDefaults:{
           renderer:$.jqplot.BarRenderer,
           pointLabels: { show: true },
           rendererOptions : {
				//padding : 8,
               varyBarColor: true,
               fillToZero: true,
				sliceMargin : 7,
				//dataLabelThreshold : 1,
				//dataLabelFormatString : '%.0f%%',
					barMargin : 30,
					//highlightMouseDown : true,
					barWidth : 40
				},
       },
       axes: {
           xaxis: {
           	renderer: $.jqplot.CategoryAxisRenderer,
		          //label: 'Warranty Concern',
		        labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
		        tickRenderer: $.jqplot.CanvasAxisTickRenderer,
		        tickOptions: {
		          labelPosition:'middle',
		            angle: data.length<=5 ? 0 : -90,
		            fontFamily:'Helvetica',
		            fontSize: '7pt'
		        }
           },
           yaxis: {
        	   min: 0,      // minimum numerical value of the axis.  Determined automatically.
               //max: Math.floor(max+(max/2)),      // maximum numverical value of the axis.  Determined automatically.
        	   pad : 1,
               autoscale:true,
		          //label: 'Occurance',
		        labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
		        tickRenderer: $.jqplot.CanvasAxisTickRenderer,
		        tickOptions: {
		        	labelPosition:'middle',
		            //angle: -30,
		            fontFamily:'Helvetica',
		            fontSize: '7pt'
		        }
           },
       cursor:{show:false}

       },
       seriesColors: [ "#F0A000","#F3BC00","#fcce07","#78e204","#1192BC","#CCC","#cfe800","#FDD900","#AC06C5","#7D1F1F","#B03431","#32C4E8","#E34B3E","#640374","#8b8a8a","#590202","#b4bb02","#babf82","#575a35","#99cc00","#999900","#996600","#9999ff","#333333"]
   });
	//$('#'+divID).highlight();
}

//Plot pie chat
function plotPieChart(divID,data,title){
	return jQuery.jqplot(divID, [data], 
			{
		title: title, 
		seriesDefaults: {
	        shadow: false, 
	        renderer: jQuery.jqplot.PieRenderer, 
	        rendererOptions: { 
	          startAngle: 180, 
	          sliceMargin: 4, 
	          showDataLabels: true } 
	      },
	      cursor:{show:false},
	      legend: { show:true, location: 'w' },
	      seriesColors: [ "#F0A000","#F3BC00","#fcce07","#78e204","#1192BC","#CCC","#cfe800","#FDD900","#AC06C5","#7D1F1F","#B03431","#32C4E8","#E34B3E","#640374","#8b8a8a","#590202","#b4bb02","#babf82","#575a35","#99cc00","#999900","#996600","#9999ff","#333333"]
	    }
);
	//$('#'+divID).highlight();
}
// Plot pie intervalCount Chart

function plotPieIntervalCountChart(divID,data,title,attr){
	$.jqplot.config.enablePlugins = true;
	var intervalCountArray=data.CountOccurenceInterval(attr), dataInterval=[],legendInterval=[];
	var serieInterval=[];
	$.each(intervalCountArray,function(index,value){
		var arr=[];arr.push(value.min+"-"+value.max);arr.push(value.count);dataInterval.push(arr);
		legendInterval.push(value.min+"-"+value.max);
		serieInterval.push(value.count);
	});
	
	return jQuery.jqplot(divID, [dataInterval], 
			{
				title: title, 
				seriesDefaults: {
			        shadow: false, 
			        renderer: jQuery.jqplot.PieRenderer, 
			        rendererOptions: { 
			          startAngle: 180, 
			          sliceMargin: 4, 
			          showDataLabels: true } 
			      }, 
			      legend: { show:true, location: 'w' },
			      seriesColors: [ "#F0A000","#F3BC00","#fcce07","#78e204","#1192BC","#CCC","#cfe800","#FDD900","#AC06C5","#7D1F1F","#B03431","#32C4E8","#E34B3E","#640374","#8b8a8a","#590202","#b4bb02","#babf82","#575a35","#99cc00","#999900","#996600","#9999ff","#333333"],
			      cursor:{show:false} 
			    });
	
}

// statistique plot chart
 function plotModelStat(modelStatTab,countIntervalTab,modelStatDiv,modelStatTitel,countIntervalDiv,countIntervalTitel){
	 $.jqplot.config.enablePlugins = true;
	//var serie=[];var legend=[];
	var serieInterval=[];var legendInterval=[];
	var dataStat=[]; dataInterval=[];
	$.each(modelStatTab,function(index,value){
		var arr=[];arr.push(index);arr.push(value);dataStat.push(arr);
		//legend.push(index);
		//serie.push(value);
	});
	var maxCount=0;
	$.each(countIntervalTab,function(index,value){
		var arr=[];arr.push(value.min+"-"+value.max);arr.push(value.count);dataInterval.push(arr);
		legendInterval.push(value.min+"-"+value.max);
		serieInterval.push(value.count);
		if(value.count>maxCount) maxCount=value.count;
	});
	var plot = plotBarChart(modelStatDiv, dataStat, modelStatTitel);
	/*modelStat = $.jqplot(modelStatDiv, [dataStat], {
		    title: modelStatTitel,
		    seriesDefaults: {
		        shadow: false, 
		        pointLabels: { show: true },
		        renderer: $.jqplot.BarRenderer,
		        rendererOptions: { 
		        	 varyBarColor: true,
	                    fillToZero: true,
	    				//padding : 8,
	    				sliceMargin : 7,
	    				barMargin : 30,
	    				barWidth : 40,
	    				showDataLabels: false
		          } 
		      }, 
		    axes: {
		      xaxis: {
		        renderer: $.jqplot.CategoryAxisRenderer,
		          //label: 'Warranty Concern',
		        labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
		        tickRenderer: $.jqplot.CanvasAxisTickRenderer,
		        tickOptions: {
		          labelPosition:'middle',
		            angle: -30,
		            fontFamily:'Helvetica',
		            fontSize: '7pt'
		        }
		      },
		      yaxis: {
		        autoscale:true,
		          //label: 'Occurance',
		        labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
		        tickRenderer: $.jqplot.CanvasAxisTickRenderer,
		        min : 0,
		        max: Math.floor(modelStatTab.max+(modelStatTab.max/2.5)),      // maximum numverical value of the axis.  Determined automatically.
		        tickOptions: {
		        	labelPosition:'middle',
		            //angle: -30,
		            fontFamily:'Helvetica',
		            fontSize: '7pt'
		        }
		      }
<<<<<<< .mine
		    },
		    cursor:{show:false}
		  });*/

	
	//$('#'+modelStatDiv).highlight();
	
	var modelStatCount = jQuery.jqplot(countIntervalDiv, [dataInterval], 
			{
				title: countIntervalTitel, 
				seriesDefaults: {
			        shadow: false, 
			        renderer: jQuery.jqplot.PieRenderer, 
			        rendererOptions: { 
			          startAngle: 180, 
			          sliceMargin: 4, 
			          showDataLabels: true 
			          } 
			      }, 
			      cursor:{show:false},
			      legend:{
				         renderer: $.jqplot.EnhancedLegendRenderer,
				         show:true,
				         showLabels: true,
				         //labels: leg,
				         rendererOptions:{
				             numberColumns:dataInterval.length/2,
				             //numberRows :1,
				             seriesToggle: 900,
				             disableIEFading: false,
				         },
				         placement:'outsideGrid',
				         location: 's',
				         marginLeft: '25px',
				         marginTop: '0px'
				     },
			      seriesColors: [ "#F0A000", "#00A1C9", "#02C926","#F3BC00","#1192BC","#CCC","#78e2004","#fcce07","#cfe800","#FDD900","#AC06C5","#7D1F1F","#B03431","#32C4E8","#E34B3E","#640374","#8b8a8a","#590202","#b4bb02","#babf82","#575a35","#99cc00","#999900","#996600","#9999ff","#333333"]
			    }
		);



} 
 
//char with  label
 function plotBarChartLabel(divID,data,title,leg,ticks,stack){
	 
	 if(ticks.length<=8){
		 return $.jqplot(divID,data,{
			    stackSeries: stack,
			     title: title,
			     seriesDefaults: {
			         renderer: $.jqplot.BarRenderer,
			         rendererOptions: { 
			                fillToZero: true,
							sliceMargin : 7,
							//barMargin : 30,
							barWidth : 20,
							showDataLabels: false
			          } 
			     },
			     legend:{
			         renderer: $.jqplot.EnhancedLegendRenderer,
			         show:true,
			         showLabels: true,
			         labels: leg,
			         rendererOptions:{
			             numberColumns:leg.length,
			             numberRows :1,
			             seriesToggle: 900,
			             disableIEFading: false,
			         },
			         placement:'outsideGrid',
			         location: 's',
			         marginLeft: '25px',
			         marginTop: '0px'
			     },
			     axes: {
			         xaxis:{
			         	renderer: $.jqplot.CategoryAxisRenderer,
					    labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
					    tickRenderer: $.jqplot.CanvasAxisTickRenderer,
			         	ticks: ticks,
					    tickOptions: {
					          labelPosition:'middle',
					            angle: -90,
					            fontFamily:'Helvetica',
					            fontSize: '7pt'
					    }
			         },
			         yaxis:{
			        	 autoscale:true,
			        	 labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
					     tickRenderer: $.jqplot.CanvasAxisTickRenderer,
			        	 min:0, 
			        	 tickOptions:{formatString:'%.2f'}
			         }
			     },
			     cursor:{show:false},
			     seriesColors: [ "#E72408", "#00A1C9"]
			 });
	 }else{
		 //var dataAxe=[]
		 return $.jqplot(divID, data, {
			    title: title,
			    legend:{
			         renderer: $.jqplot.EnhancedLegendRenderer,
			         show:true,
			         showLabels: true,
			         labels: leg,
			         rendererOptions:{
			             numberColumns:leg.length,
			             numberRows :1,
			             seriesToggle: 900,
			             disableIEFading: false,
			         },
			         placement:'outsideGrid',
			         location: 's',
			         marginLeft: '25px',
			         marginTop: '0px'
			     },
			    series: [{
			        // label: 'Google, Inc.',
			    	
			        neighborThreshold: 0
			    }],
			    axes: {
			        xaxis: {
			        	renderer: $.jqplot.CategoryAxisRenderer,
					    labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
					    tickRenderer: $.jqplot.CanvasAxisTickRenderer,
			         	ticks: ticks,
					    tickOptions: {
					          labelPosition:'middle',
					            angle: -90,
					            fontFamily:'Helvetica',
					            fontSize: '7pt'
					    }
			        },
			        yaxis: {
			        	 autoscale:true,
			        	 labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
					     tickRenderer: $.jqplot.CanvasAxisTickRenderer,
			        	 min:0, 
			        	 tickOptions:{formatString:'%.2f'}
			        }
			    },
			    cursor:{zoom:true},
			    highlighter:{show:true}
			});
	 }
	 
 
 }
 
 //
 function plotProgressChartLegend(divID,data,title,leg){
	 if(data.length==0) return false;
	 var startDate=0,endDate=0;
	 $.each(data,function(index,value){
		 if(value.length>0){
			 startDate=value[0][0];endDate=value[value.length-1][0];
			return false;
		 }
	 });
	 if(startDate==0 || endDate==0) return false;
	 return $.jqplot(divID, data, {
		    title: title,
		    legend:{
		           renderer: $.jqplot.EnhancedLegendRenderer,
		           show:true,
		           labels:leg,
		           rendererOptions:{
		               numberColumns : leg.length
		           },
					 placement:'outsideGrid',
				     location: 'n',
				     marginLeft: '25px',
				     marginTop: '0px'
		    },
		    series: [{
		        neighborThreshold: 0
		    }],
		    axes: {
		        xaxis: {
		          renderer:$.jqplot.DateAxisRenderer,
		          rendererOptions:{
	              tickRenderer:$.jqplot.CanvasAxisTickRenderer},
	              tickOptions:{formatString:'%#d/%#m/%Y', fontSize:'8pt', fontFamily:'Tahoma', angle:-90, fontWeight:'normal', fontStretch:1},
		         // min:'August 1, 2007',
		          tickInterval: getStepProgressChart(startDate, endDate),
		          //tickOptions:{formatString:"%#d/%#m/%Y"}
		        },
		        yaxis: {
		        	 labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
				     tickRenderer: $.jqplot.CanvasAxisTickRenderer,
		        	autoscale:true,
		           // renderer: $.jqplot.LogAxisRenderer,
		           tickOptions:{formatString:'%.2f'},
		           rendererOptions: { forceTickAt0: true},
		           //min : 0
		        }
		    },
		    cursor:{zoom:true},
		    highlighter:{show:true}
		});
 }
 
 function plotProgressChart(divID,data,title){
	 if(data.length==0) return false;
	 var startDate=data[0][0][0],endDate=data[0][data[0].length-1][0];
	 $.jqplot(divID, data, {
		    title: title,
		    series: [{
		        neighborThreshold: 0
		    }],
		    axes: {
		        xaxis: {
		          renderer:$.jqplot.DateAxisRenderer,
		          rendererOptions:{
	              tickRenderer:$.jqplot.CanvasAxisTickRenderer},
	              tickOptions:{formatString:'%#d/%#m/%Y', fontSize:'8pt', fontFamily:'Tahoma', angle:-90, fontWeight:'normal', fontStretch:1},
		          tickInterval:  getStepProgressChart(startDate, endDate),
		          //tickOptions:{formatString:"%Y/%#m/%#d"}
		        },
		        yaxis: {
		        	labelRenderer: $.jqplot.CanvasAxisLabelRenderer,
				     tickRenderer: $.jqplot.CanvasAxisTickRenderer,
		           // renderer: $.jqplot.LogAxisRenderer,
		           tickOptions:{formatString:'%.2f'},
		           rendererOptions: { forceTickAt0: true},
		           //min : 0
		        }
		    },
		    cursor:{zoom:true},
		    highlighter:{show:true}
		});
	 
	 
 }
 
 function getStepProgressChart(startDate,endDate){
	 var days=(new Date(endDate)-new Date(startDate))/1000/60/60/24;
	 var step="1 day";
	 switch (true) {
	case (days<=31):
		step="1 day";
		break;
	case (days<=60):
		step="3 days";
		break;
	case (days<=90):
		step="5 days";
		break;
	case (days<=120):
		step="8 days";
		break;
	case (days<=150):
		step="10 days";
		break;
	case (days<=180):
		step="12 days";
		break;
	case (days<=210):
		step="15 days";
		break;
	case (days<=240):
		step="18 days";
		break;
	case (days<=270):
		step="21 days";
		break;
	case (days<=300):
		step="25 days";
		break;
	case (days<=330):
		step="30 days";
		break;
	case (days<=360):
		step="40 days";
		break;
	default:
		step="1 month";
		break;
	}
	 return step;
 }
 
//valid ip adress
 String.prototype.isValidIpAddress = function(){
	 var array=this.split(".");
	 if(array.length!=4 ){
		 return false;
	 }else{
		 //if(isNaN(array[0]) || array[0]<1) return false;
		 for(var i=0;i<array.length;i++){
			 if(isNaN(array[i]) || array[i]<0 || array[i]>255) return false; 
		 }
	 }
	 return true;
 };

 function waitExec(delay) {
	    var startTime = new Date();
	    var endTime = null;
	    do {
	    endTime = new Date();
	    } while ((endTime - startTime) < delay);
}
//function 
 
 